! ==============================================================================
! This file is part of GMCORE since 2019.
!
! GMCORE is a dynamical core for atmospheric model.
!
! GMCORE is distributed in the hope that it will be useful, but WITHOUT ANY
! WARRANTY. You may contact authors for helping or cooperation.
! ==============================================================================

module mars_vert_coord_mod

  use flogger
  use const_mod
  use latlon_mesh_mod
  use latlon_parallel_types_mod

  implicit none

  private

  public mars_vert_coord_emars28
  public mars_vert_coord_nasa24

contains

  subroutine mars_vert_coord_emars28(p0, ptop, hyai, hybi)

    real(r8), intent(out) :: p0
    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: hyai(29)
    real(r8), intent(out) :: hybi(29)

    if (global_mesh%full_nlev /= 28 .and. proc%is_root()) then
      call log_error('nlev should be 28 in namelist!')
    end if

    hyai = [          &
      0.02_r8       , & !  1
      0.05738127_r8 , & !  2
      0.1958398_r8  , & !  3
      0.5922958_r8  , & !  4
      1.566023_r8   , & !  5
      2.445497_r8   , & !  6
      2.768375_r8   , & !  7
      2.885169_r8   , & !  8
      2.917223_r8   , & !  9
      2.908704_r8   , & ! 10
      2.859894_r8   , & ! 11
      2.768765_r8   , & ! 12
      2.632705_r8   , & ! 13
      2.450922_r8   , & ! 14
      2.226681_r8   , & ! 15
      1.968468_r8   , & ! 16
      1.689483_r8   , & ! 17
      1.405581_r8   , & ! 18
      1.132426_r8   , & ! 19
      0.8828918_r8  , & ! 20
      0.6654847_r8  , & ! 21
      0.4840102_r8  , & ! 22
      0.3382412_r8  , & ! 23
      0.225107_r8   , & ! 24
      0.1399572_r8  , & ! 25
      0.07761155_r8 , & ! 26
      0.0330855_r8  , & ! 27
      0.002_r8      , & ! 28
      0.0_r8          & ! 29
    ]
    hybi = [          &
      0.0_r8        , & !  1
      0.0_r8        , & !  2
      0.0_r8        , & !  3
      0.0_r8        , & !  4
      0.0_r8        , & !  5
      0.001936639_r8, & !  6
      0.007441913_r8, & !  7
      0.01622727_r8 , & !  8
      0.02707519_r8 , & !  9
      0.043641_r8   , & ! 10
      0.0681068_r8  , & ! 11
      0.1028024_r8  , & ! 12
      0.1497195_r8  , & ! 13
      0.2098713_r8  , & ! 14
      0.2827023_r8  , & ! 15
      0.3658161_r8  , & ! 16
      0.4552023_r8  , & ! 17
      0.545936_r8   , & ! 18
      0.6331097_r8  , & ! 19
      0.7126763_r8  , & ! 20
      0.7819615_r8  , & ! 21
      0.8397753_r8  , & ! 22
      0.8862035_r8  , & ! 23
      0.9222317_r8  , & ! 24
      0.9493454_r8  , & ! 25
      0.9691962_r8  , & ! 26
      0.9833726_r8  , & ! 27
      0.9932694_r8  , & ! 28
      1.0_r8          & ! 29
    ]

    p0 = 701
    hyai = hyai / p0
    ptop = p0 * hyai(1)

  end subroutine mars_vert_coord_emars28

  subroutine mars_vert_coord_nasa24(ptop, sigi, sig)

    real(r8), intent(out) :: ptop
    real(r8), intent(out) :: sigi(25)
    real(r8), intent(out) :: sig(24)

    sigi = [                   &
      0.0000000000000000d0   , & ! 1
      1.2370000000000000d-004, & ! 2
      3.4230000000000003d-004, & ! 3
      7.2999999999999996d-004, & ! 4
      1.4177000000000000d-003, & ! 5
      2.6376000000000004d-003, & ! 6
      4.7997999999999999d-003, & ! 7
      8.6569999999999998d-003, & ! 8
      1.4385700000000000d-002, & ! 9
      2.3814399999999999d-002, & ! 10
      3.9358699999999996d-002, & ! 11
      6.4984899999999998d-002, & ! 12
      0.10724580000000000d0  , & ! 13
      0.17688760000000001d0  , & ! 14
      0.29178419999999999d0  , & ! 15
      0.44484750000000001d0  , & ! 16
      0.60207440000000001d0  , & ! 17
      0.73729350000000005d0  , & ! 18
      0.85853470000000009d0  , & ! 19
      0.93043220000000004d0  , & ! 20
      0.97400000000000009d0  , & ! 21
      0.98800000000000010d0  , & ! 22
      0.99600000000000011d0  , & ! 23
      0.99900000000000011d0  , & ! 24
      1.00000000000000000d0  ]   ! 25

    sig = [                    &
      6.1849999999999999d-005, & ! 1
      2.3300000000000003d-004, & ! 2
      5.3614999999999999d-004, & ! 3
      1.0738499999999999d-003, & ! 4
      2.0276500000000002d-003, & ! 5
      3.7187000000000001d-003, & ! 6
      6.7283999999999998d-003, & ! 7
      1.1521350000000000d-002, & ! 8
      1.9100050000000000d-002, & ! 9
      3.1586549999999998d-002, & ! 10
      5.2171799999999997d-002, & ! 11
      8.6115350000000007d-002, & ! 12
      0.14206669999999999d0  , & ! 13
      0.23433589999999999d0  , & ! 14
      0.36831585000000000d0  , & ! 15
      0.52346095000000004d0  , & ! 16
      0.66968395000000003d0  , & ! 17
      0.79791410000000007d0  , & ! 18
      0.89448345000000007d0  , & ! 19
      0.95221610000000001d0  , & ! 20
      0.98100000000000009d0  , & ! 21
      0.99200000000000010d0  , & ! 22
      0.99750000000000005d0  , & ! 23
      0.99950000000000006d0  ]   ! 24
    ptop = 0.08d0 ! Pa

  end subroutine mars_vert_coord_nasa24

end module mars_vert_coord_mod
